<template>
	<view class="box">
		<view class="contented">
			<view class="top">
				<view class="count flex_wrap row_middle row_center">
					<text>张数</text>
					<text class="countt">1</text>
				</view>
				<view>
					<u-text :text="detailInfo.favorableTitle" size="56rpx" color="#FF3C3C" align="center" margin="18rpx 0" />
					<u-text :text="detailInfo.favorableDescription" size="28rpx" color="#3D3D3D" align="center" />
					<u-text :text="`有效期限至` +  $u.timeFormat(detailInfo.cutOffTime, 'yyyy.mm.dd')" size="28rpx" color="#666" align="center" margin="16rpx 0 48rpx" />
				</view>
				<view class="u-line">
					<u-line dashed color="#D8D8D8" />
				</view>
			</view>
			<u-gap height="64rpx"></u-gap>
			<view class="bottom">
				<view class="list flex_wrap flex_column">
					<u-row align="top">
						<u-col span="3"><u--text text="适用规则：" color="#666" size="28rpx" /></u-col>
						<u-col span="8"><u--text :text="detailInfo.favorableDescription" color="#666"
								size="28rpx" /></u-col>
					</u-row>
					<u-gap height="32rpx" />
					<u-row align="top">
						<u-col span="3"><u--text text="店铺地址：" color="#666" size="28rpx" /></u-col>
						<u-col span="8"><u--text text="--" color="#1682FF"
								size="28rpx" /></u-col>
					</u-row>
				</view>
				<u-gap height="64rpx" />
				<view>
					<u-button
						:text="show ? '确认使用' : '已核销'"
						shape="circle"
						border="none"
						color="#1682FF"
						@click="show ? writeOff() : toCoupon()"
					/>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {getInfoByUniqueId,cancelCouponByUniqueId} from "@/api/coupon.js";
	import { getFavorableInfoById ,analyzeACouponRedisKey,cancelACoupon} from "@/api/order.js";
	import { baseUrl } from "@/config/tendIdConfig"
	export default {
		data() {
			return {
				favorableId:'',
				userId:'',
				detailInfo:'',
				baseSrc: "",
				show:true,
				uniqueId:''
			};
		},
		onLoad(options) {
			console.log(options,"扫码参数")	
			this.uniqueId = options.scene
			this.getCouponDetail(this.uniqueId)
		},
		methods: {
			getCouponDetail(uniqueId){
				getInfoByUniqueId(uniqueId).then((res) => {
					if (res.code === 200 && res.data) {
					   this.detailInfo = res.data
					}
				});
			},
			
			async writeOff(){
				await cancelCouponByUniqueId(this.uniqueId)
				    .then(async (res) => {
				      uni.$u.toast('核销成功！')
				      this.show = false
				    })
				    .catch((error) => {
				        uni.$u.toast(msg);
				    });
			},
			
			toCoupon(){
				uni.reLaunch({
					url: "/pages/counselling/index"
				})
			}
		},
	};
</script>

<style lang="scss">
	page {
		background-color: #1E2137;
	}

	.box {
		padding: 32rpx 28rpx;
	}

	.contented {
		background-image: url('https://oneredhealth.oss-cn-hangzhou.aliyuncs.com/2024/01/09/717a56be5f3e48a791943c3a3b21c8fd.png');
		width: 100%;
		background-repeat: no-repeat;
		height: 716rpx;
		background-size: 100% 100%;
		position: relative;
	}
	.imgd{
		position: absolute;
		top: 0;
		right: 0;
	}
	.top{
		padding: 44rpx 28rpx 0;
	}
	.bottom{
		padding: 0 28rpx 64rpx;
		background-color: #fff;
		border-radius: 12rpx;
	}

	.count {
		font-size: 32rpx;
		color: #DCB210;

		.countt {
			font-size: 48rpx;
			margin-left: 12rpx;
		}
	}
	.counted {
		font-size: 32rpx;
		color: #3D3D3D;
	
		.countt {
			font-size: 48rpx;
			margin-left: 12rpx;
		}
	}
.u-line{
	padding: 0 30rpx;
}
</style>